{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" role="form" action="" method="post" enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row">
                            <label for="role" class="col-sm-2 col-form-label ">角色</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <select class="form-control select2bs4" id="role" name="role[]" data-placeholder="请选择角色" multiple>
                                    <option value="">请选择角色</option>
                                    {foreach name='role_list' id='item'}
                                    <option value="{$item.id}" {if isset($data) && in_array($item.id,$data.role)}selected{/if}>
                                    {$item.name}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('.select2bs4').select2({
                                theme: 'bootstrap4'
                            })
                        </script>

                        <div class="form-group row">
                            <label for="nickname" class="col-sm-2 col-form-label ">昵称</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="text" class="form-control"
                                       id="nickname" name="nickname" value="{$data.nickname|default=''}"
                                       placeholder="请输入昵称">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="username" class="col-sm-2 col-form-label ">账号</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="text" class="form-control"
                                       id="username" name="username" value="{$data.username|default=''}"
                                       placeholder="请输入账号">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-sm-2 col-form-label ">密码</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="password" class="form-control"
                                       id="password" name="password" value="{$data.password|default=''}"
                                       placeholder="请输入密码">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="status" class="col-sm-2 col-form-label ">是否启用</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="switch fieldSwitch" id="status" name="status"
                                       value="{$data.status|default='1'}" hidden/>
                                <input type="checkbox" class="input-switch" id="statusSwitch" value="1"
                                       {if(!isset($data) ||$data.status==1)}checked{/if}/>
                            </div>

                        </div>
                        <script>
                            $('#statusSwitch').bootstrapSwitch({
                                onColor : 'success',
                                offColor : 'danger',
                                onText : '是',
                                offText : '否',
                                onSwitchChange: function (event, state) {
                                    $('#status').val(state ? '1' : '0');
                                }
                            });
                        </script>

                    </div>
                    <div class="card-footer">

                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create" name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>

                </form>

            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
            'role[]': {
                required: true,
            },
            'username': {
                required: true,
            },
            'nickname': {
                required: true,
            },
            'password': {
                required: true,
            },


        },
        messages: {
            'role[]': {
                required: "请选择角色",
            },
            'username': {
                required: "用户名不能为空",
            },
            'nickname': {
                required: "昵称不能为空",
            },
            'password': {
                required: "密码不能为空",
            },
        }
    });
</script>

{/block}